<?php
    require_once(dirname(__FILE__).'/common/config.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <!-- 浏览器中页面将以原始大小显示，并不允许缩放 -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <!-- 网站开启对web app程序的支持 -->
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>学子礼品</title>
    <link rel="stylesheet" href="css/public.css?v=<?php echo $v;?>">
    <link rel="stylesheet" href="css/style.css?v=<?php echo $v;?>">
</head>
<body>
    <div class="content" id="app" v-cloak>
        <ul>
            <li v-for="(item, index) in goodslist">
                <div v-bind:data-goodsid="item.id" v-on:click="choice">{{item.name}}</div>
            </li>
        </ul>
        <div v-show="isshow1">
            手机号:<input type="text" name="game_userid" id="game_userid_1">
        </div>
        <div v-show="isshow2">
            账号:<input type="text" name="game_userid" id="game_userid_2">
        </div>
        <button v-on:click="subData" v-bind:data-goodstype="goodstype">提交</button>
    </div>
</body>
<script src="js/jquery.min.js"></script>
<script src="js/vue.min.js"></script>
<script src="js/mint-ui.min.js"></script>
<script>
    var vm = new Vue({
        el: '#app',
        data:{
            /*用户标识*/
            userid:0,
            /*选择礼品id*/
            goodsid:0,
            /*礼品类型0.卡密提取1.手机号2.账号*/
            goodstype:0,
            /*是否显示*/
            isshow1:false,
            isshow2:false,
            /*礼品列表*/
            goodslist:[]
        },
        methods:{
            /*获取礼品列表*/
            getGoodsList:function()
            {
                let url = 'ajax_do.php?act=getgoodslist';
                var that = this;
                $.ajax({
                    type:'post',
                    dataType:'json',
                    url:url,
                    data:{
                        userid:vm.userid
                    },
                    success:function(res)
                    {
                        if(res.code == 0)
                        {
                            that.goodslist = res.info;
                        }
                    }
                });
            },
            /*选择礼品*/
            choice:function(e)
            {
                console.log($(e.currentTarget).attr('data-goodsid'))
                vm.goodsid = parseInt($(e.currentTarget).attr('data-goodsid'));
                switch(vm.goodsid)
                {
                    /*显示账号*/
                    case 1:
                    case 2:
                    case 3:
                    case 6:
                        vm.isshow1 = false;
                        vm.isshow2 = true;
                        vm.goodstype = 2;
                        break;
                    /*显示手机号*/
                    case 5:
                        vm.isshow1 = true;
                        vm.isshow2 = false;
                        vm.goodstype = 1;
                        break;
                    default:
                        vm.isshow1 = false;
                        vm.isshow2 = false;
                        vm.goodstype = 0;     
                }
            },
            /*提交数据*/
            subData:function(e)
            {
                /*类型*/
                let goodstype = parseInt($(e.currentTarget).attr('data-goodstype'));
                let game_userid = '';
                if(goodstype > 0)
                {
                    game_userid = $("#game_userid_"+goodstype).val();
                }
                let url = "ajax_do.php?act=recharge";
                var that = this;
                $.ajax({
                    type:'post',
                    dataType:'json',
                    url:url,
                    data:{
                        userid:vm.userid,
                        game_userid:game_userid,
                        goods_id:vm.goodsid,
                        goodstype:goodstype
                    },
                    success:function(res)
                    {
                        
                    }
                });
            }
        }
    });
    /*获取礼品列表*/
    vm.getGoodsList();
</script>
</html>